/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
/**
 *
 * @author Al Quthsi
 */
public class GamerCanvast extends GameCanvas implements Runnable{
private boolean isPlay;
public long delay;
private int currentX, currentY;
private int width,height;

public GamerCanvast(){
    super(true);
    width = getWidth();
    height = getHeight();
    currentX = width/2;
    currentY = height/2;
    delay = 20;

}public void start(){
    isPlay=true;
    Thread T = new Thread(this);
    T.start();
}

public void stop(){
    isPlay = false;
}

//Main game loop

    public void run() {
Graphics g = getGraphics();
while(isPlay == true){
    input();
    drawScreen(g);
    try{
        Thread.sleep(delay);
    }catch(InterruptedException IE){

}
}
    }

    private void drawScreen(Graphics g) {
        g.setColor(0xffffff);
        g.fillRect(0, 0, width, height);
        g.setColor( 0x0000ff);
        g.drawString("X", currentX, currentY, Graphics.TOP|Graphics.LEFT);
        flushGraphics();
    }

    private void input() {
        int keyState = getKeyStates();

        //Kiri
        if((keyState & LEFT_PRESSED) !=0){
            currentX = Math.max(0, currentX-1);
        }

        if((keyState & RIGHT_PRESSED)!=0){
            currentX = Math.min(width, currentX+1);
        }

        if((keyState & UP_PRESSED)!=0){
            currentY = Math.max(0, currentY-1);
        }

        if((keyState & DOWN_PRESSED)!=0){
            currentY = Math.min(height, currentY + 1);
        }
    }


}
